const MAJOR_GRID_SPACING = 50
const MINOR_GRID_SPACING = 10

class Grid {
  maingrid
  origin
  width
  height
  origincount
  draw(
    drawCommands,
    {
      perspective,
      view,
      width,
      height,
      major = MAJOR_GRID_SPACING,
      minor = MINOR_GRID_SPACING,
    }
  ) {
    if (
      !this.maingrid ||
      !this.origin ||
      this.width !== width ||
      this.height !== height
    ) {
      this.width = width
      this.height = height

      const c = []

      c.push(0, 0, 0, this.width, 0, 0)
      c.push(0, -this.height, 0, this.width, -this.height, 0)
      c.push(0, -this.height, 0, 0, 0, 0)
      c.push(this.width, -this.height, 0, this.width, 0, 0)

      this.origin = new Float32Array(c)
      this.origincount = c.length / 3
    }

    drawCommands.basic({
      perspective,
      view,
      position: this.origin,
      offset: 0,
      count: this.origincount,
      color: [0, 0, 0, 1],
      scale: [1, 1, 1],
      translate: [0, 0, 0],
      primitive: drawCommands.gl.LINES,
    })
  }
}
